<?php

namespace app\common\model;

use think\facade\Cache;
use think\Model;

class ConfigPubModel extends Model
{
    protected static function init()
    {
        ConfigPubModel::afterUpdate(function ($user) {
            Cache::store('redis')->rm('go_webapi_ConfigPub');
        });
    }

    public static function conf()
    {
        $data = Cache::store('redis')->remember('go_webapi_ConfigPub', function () {
            if (!$model = static::where('id', 1)->find()) {
                return '{}';
            }
            return json_encode($model->toArray());
        });

        return json_decode($data, true) ?? [];
    }
}